package cn.com.task;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import cn.com.api.mapper.ApiT_user_cash_recordsMapper;
import cn.com.api.service.*;
import cn.com.util.DateUtil;

@Component
public class Dispatch {

	@Autowired
	private ApiT_member_task_processService apiT_member_task_processService;
	@Autowired
	private ApiU_matchService apiU_matchService;
	@Autowired
	private ApiU_bonusService apiU_bonusService;
	@Autowired
	private ApiT_user_cash_recordsService apiT_user_cash_recordsService;

	private static Logger logger = Logger.getLogger(Dispatch.class);

	/**
	 * 定时任务，更新每位合伙人的任务完成进度 每天一点执行
	 */
	// @Scheduled(cron = "0 0 1 * * *")
	public void updateTaskProcesss() {
		System.out.println("=============更新合伙人的任务进度开始：" + DateUtil.nowTimeToString());
		apiT_member_task_processService.updateTaskProcesss();
		System.out.println("=============更新合伙人的任务进度结束：" + DateUtil.nowTimeToString());
	}

	/**
	 * 定时任务，每天更新投票结束的赛事，统计赛事作品的获奖信息。 每天一点执行
	 */
	// @Scheduled(cron = "0 0 1 * * *")
	public void tongJiMatch() {
		System.out.println("=============更新赛事开始：" + DateUtil.nowTimeToString());
		try {
			apiU_matchService.tongJiMatch();
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		System.out.println("=============更新赛事结束：" + DateUtil.nowTimeToString());
	}

	/**
	 * 统计没领取的红包。（收回红包金额）
	 */
	// @Scheduled(cron = "0 0 1 * * *")
	public void takeBackBonus() {
		System.out.println("=============收回红包开始：" + DateUtil.nowTimeToString());
		try {
			// 表示过期时间，单位为小时
			Integer hours = 24;
			apiU_bonusService.takeBackBonus(hours);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		System.out.println("=============收回红包结束：" + DateUtil.nowTimeToString());
	}

	/**
	 * 回收未领取的转账
	 */
	// @Scheduled(cron = "0 0 1 * * *")
	public void takeBackTransfer() {
		System.out.println("=============收回转账开始：" + DateUtil.nowTimeToString());
		try {
			// 表示过期时间，单位为小时
			Integer hours = 24;
			apiT_user_cash_recordsService.takeBackTransfer(hours);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		System.out.println("=============收回转账结束：" + DateUtil.nowTimeToString());
	}

}
